﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common
{
    public /*abstract*/ class Variable 
    {
        #region Members
        private string name;
        private string description;      
        protected string currentValue;
        private string defaultValue;
        private int id;        
        protected bool isChanged;
        protected Type type;

        public event EventHandler VariableChanged;
        public event EventHandler VariableInitialyzed;
        #endregion

        #region Properties
        public int Id
        {
            get { return id; }
            set { id = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }   // Vanya Edit
        }

        public bool IsChanged
        {
            get { return isChanged; }
            set { isChanged = value; }
        }
        
        public string DefaultValue
        {
            get { return defaultValue; }
            set { defaultValue = value; }
        }

        public virtual string CurrentValue
        {
            get { return currentValue; }
            set 
            {
                if (currentValue != value)
                {
                    currentValue = value;
                    isChanged = true;
                }

            }
        }

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        public Type Type
        {
            get { return type; }
            set { type = value; }   //Vanya Edit
        }
        #endregion

        #region Constructors
        public Variable(string name, string description, string defValue, int ID)
        {
            this.id = ID;
            this.name = name;
            this.description = description;
            defaultValue = defValue;               
            isChanged = false;//this moment needs future review
            currentValue = defaultValue;
            if (VariableInitialyzed != null)
            {
                VariableInitialyzed(this,new EventArgs() );
            }
        }
        #endregion

        public void ConfirmChanges()
        {
            if (isChanged)
            {
                if (VariableChanged != null)
                {
                    VariableChanged(this, new EventArgs());
                }
                isChanged = false;
            }
            else
            {
                throw new Exception("Variable wasn't changed ");
            }
        }
    }
}
